$(function() {
    var form = layui.form
    var layer = layui.layer


    form.verify({
        pwd: [
            /^[\S]{6,12}$/, '密码必须6到12位，且不能出现空格'
        ],
        samePwd: function(value) {
            var pwd = $('[name=newPwd]').val()
            if (value !== pwd) return "两次密码输入不一致"
        }
    })
    $('#form_userPwd').submit(function(e) {
        e.preventDefault();
        var data = $(this).serialize()
        $.ajax({
            method: 'POST',
            url: '/my/updatepwd',
            data: data,
            success: function(res) {
                if (res.status !== 0) return layer.msg('修改密码失败!')
                layer.msg('修改密码成功!')
                $('#form_userPwd')[0].reset()
            }
        })
    })
})